{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "583300c7",
   "metadata": {},
   "source": [
    "### 试卷C答案及解析"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "08085dca",
   "metadata": {},
   "source": [
    "####  **查找“媒体”的次数** \n",
    "  "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5511d7bb",
   "metadata": {},
   "source": [
    "* 请勿改动变量名freq_table_phrase，过程可自行书写\n",
    "\n",
    "* 答案：\n",
    "```\n",
    "phrase = \"媒体\"\n",
    "freq_table_phrase= text.count(phrase)       # str.count()\n",
    "freq_table_phrase\n",
    "```\n",
    "\n",
    "*   结果：1527\n",
    "\n",
    "*   知识点：\n",
    "    * 1.  使用变量\n",
    "    * 2. count（使用在序列数据当中，如字符串，列表，元组，可快速查询词频）\n",
    "*    两个思路： \n",
    "      * 1. python/doc  \n",
    "      * 2. 百度/必应浏览器搜索关键词\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fa51f633",
   "metadata": {},
   "source": [
    "####  **用中文\"。\"拆分,生成list_split列表，每一个句子是一个独立的列表元素** "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "de7c2682",
   "metadata": {},
   "source": [
    "* 请勿改动变量名list_split，过程可自行书写\n",
    "* 题目：\n",
    "```\n",
    "list_split = text.split(\"。\")\n",
    "# list_split\n",
    "```\n",
    "\n",
    "* 答案；\n",
    "```\n",
    "\"python\".split()\n",
    "```\n",
    "\n",
    "* 效果：['python']\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b824962e",
   "metadata": {},
   "source": [
    "####  **取出第十个句子** "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5c95864f",
   "metadata": {},
   "source": [
    "* 请勿改动变量名the_10_phrase，过程可自行书写\n",
    "* 首先：\n",
    "```# 一共有多少句？\n",
    "  len(list_split)\n",
    "```\n",
    "* 结果：1033\n",
    "\n",
    "* 答案：\n",
    "```\n",
    "the_10_phrase= list_split[9]\n",
    "the_10_phrase\n",
    "```\n",
    "\n",
    "* 结果：'在媒体融合中,优质内容资源的合理运营是传统出版企业实现转型升级的基础'\n",
    "\n",
    "*  知识点：\n",
    "    1. 列表的取值[index], （切片-没考，可以回顾）\n",
    "    2. 清楚列表的序列是从0开始的"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b884d709",
   "metadata": {},
   "source": [
    "####  **请找出text中所有\"媒体\"关键字前面的两个字符** "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0a1b4220",
   "metadata": {},
   "source": [
    "* 提示：\n",
    "   * 先找出所有媒体位置列表 position_all，（20分）\n",
    "   * 再找出所有 \"媒体\"关键字前面的两个字符列表 content_all，\n",
    "   \n",
    "* 答案：\n",
    "```\n",
    "position_all=[]\n",
    "for i,j in enumerate(text):\n",
    "    if j == '媒':\n",
    "        if text[i+1] == '体':\n",
    "            position_all.append(i)\n",
    "```\n",
    "* 知识点： \n",
    "   1. enumerate 作为枚举，对序列数据进行  索引值 和 值（一起循环打印结果）\n",
    "   2. list列表的新增 append\n",
    "   \n",
    "   \n",
    "```\n",
    "content_all=[]\n",
    "for i in position_all:\n",
    "    content_all.append(text[i-2:i])\n",
    " \n",
    "```\n",
    "\n",
    "*  知识点：\n",
    "   1. 序列数据的切片\n",
    "   2. 列表的新增 append"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e481882d",
   "metadata": {},
   "source": [
    "####  **统计text中所有\"媒体\"关键字前面的两个字符的出现次数（即词频）** "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1623bd18",
   "metadata": {},
   "source": [
    "* 答案提示：{'提出': 2, '应新': 3, '重新': 1, '用新': 3, '建新': 1,...}\n",
    "\n",
    "* 答案：\n",
    "```\n",
    "found = {}\n",
    "for i in content_all:\n",
    "    found[i]=content_all.count(i)\n",
    "```\n",
    "* 知识点:\n",
    "    字典的内容——\n",
    "   1. 字典的新建（3种方法其中一种）  dict_name[key] = value (常用)\n",
    "   2. 列表的词频 （序列数据的词频） count\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f7f853ed",
   "metadata": {},
   "source": [
    "####  **找出text中所有\"媒体\"关键字前面的两个字符的次数排在前八的关键词，作为一个新的字典输出** "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "72e26ba1",
   "metadata": {},
   "source": [
    "* 答案：\n",
    "\n",
    "```\n",
    "# 第一步：\n",
    "fonud_values_list = list(found.values())\n",
    "print(fonud_values_list)\n",
    "```\n",
    "* 效果：[2, 3, 1, 3, 1, 1, 169, 1, 21, 15, 1, 6, 2, 1, 5, 1, 8, 2, 5, 38, 1, 2, 1, 3, 9, 5, 16, 15, 1, 2, 1, 8, 1, 1, 2, 2, 1, 2, 1, 1, 1, 1, 1, 2, 3, 1, 1, 1, 1, 3, 1, 1, 2, 3, 2, 1, 1, 4, 5, 3, 1, 6, 5, 1, 1, 1, 1, 1, 6, 1, 2, 4, 1, 3, 2, 6, 6, 15, 6, 3, 1, 2, 1, 2, 1, 1, 1, 2, 1, 1, 1, 38, 1, 1, 13, 5, 2, 1, 1, 1, 13, 1, 2, 2, 19, 2, 2, 2, 1, 3, 4, 4, 1, 4, 1, 1, 21, 2, 1, 10, 1, 1, 1, 1, 5, 3, 1, 1, 3, 1, 2, 1, 1, 5, 1, 1, 2, 2, 4, 1, 2, 7, 1, 4, 1, 1, 3, 4, 4, 3, 4, 1, 3, 1, 2, 4, 1, 1, 1, 3, 1, 1, 1, 1, 2, 2, 9, 15, 1, 5, 1, 2, 22, 1, 1, 1, 1, 2, 1, 1, 5, 1, 1, 1, 3, 7, 5, 1, 1, 1, 1, 3, 1, 1, 2, 2, 1, 2, 1, 3, 2, 4, 1, 1, 2, 8, 2, 4, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 3, 2, 1, 1, 2, 1, 1, 2, 12, 2, 1, 8, 6, 2, 1, 1, 2, 3, 4, 1, 1, 1, 1, 3, 7, 1, 1, 2, 2, 5, 1, 2, 2, 1, 1, 3, 1, 6, 1, 1, 1, 1, 1, 2, 2,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1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 2, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1]\n",
    "\n",
    "```\n",
    "# 第二步;\n",
    "fonud_values_list.sort(reverse=True)\n",
    "```\n",
    "```\n",
    "# 第三步：\n",
    "fonud_values_list[:8]\n",
    "```\n",
    "* 结果：[169, 38, 38, 22, 21, 21, 19, 16]\n",
    "\n",
    "```\n",
    "# 最终：\n",
    "top8_found = {}\n",
    "for k,v in found.items():\n",
    "#     print(k,v)\n",
    "    if v in fonud_values_list[:8]:\n",
    "#         print(k,v)\n",
    "        top8_found[k]=v\n",
    "top8_found\n",
    "```\n",
    "\n",
    "* 结果：{'传统': 169,\n",
    "   '级融': 21,\n",
    "   '新兴': 38,\n",
    "   '智能': 16,\n",
    "  '主流': 38,\n",
    "  '推动': 19,\n",
    "  '电视': 21,\n",
    "  '广电': 22}"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
